﻿namespace SERFLITEMAX20.Core
{
    using SERFLITEMAX20;
    using System;
    using System.Xml;

    public class CorpseObject : BaseObject
    {
        private float facing;
        private string name;
        private float x;
        private float y;
        private float z;

        public CorpseObject(int ptr, Main sender) : base(ptr, sender)
        {
            this.Update();
        }

        public override XmlElement GetXMLElement(XmlDocument pDom)
        {
            XmlElement xMLElement = base.GetXMLElement(pDom);
            xMLElement.SetAttribute("name", this.Name);
            xMLElement.SetAttribute("x", this.x.ToString());
            xMLElement.SetAttribute("y", this.y.ToString());
            xMLElement.SetAttribute("z", this.z.ToString());
            xMLElement.SetAttribute("facing", this.facing.ToString());
            xMLElement.SetAttribute("flags", this.Flags.ToString());
            xMLElement.SetAttribute("isdead", "True");
            return xMLElement;
        }

        public override bool Update()
        {
            bool flag = base.Update();
            if (flag)
            {
                this.x = base.sender.Memory.ReadFloat(base.ptrBase + Addresses.OFFSET_Corpse_PosX);
                this.y = base.sender.Memory.ReadFloat(base.ptrBase + Addresses.OFFSET_Corpse_PosY);
                this.z = base.sender.Memory.ReadFloat(base.ptrBase + Addresses.OFFSET_Corpse_PosZ);
                this.facing = base.sender.Memory.ReadFloat(base.ptrBase + Addresses.OFFSET_Corpse_Facing);
                return flag;
            }
            this.x = this.y = this.z = this.facing = 0f;
            return flag;
        }

        public override int DisplayID
        {
            get
            {
                return base.ReadStorageInt(UpdateFields.ITEM_FIELD_CREATOR);
            }
        }

        public override int DynFlags
        {
            get
            {
                return base.ReadStorageInt(UpdateFields.ITEM_FIELD_ENCHANTMENT_5_1);
            }
        }

        public override float Facing
        {
            get
            {
                return this.facing;
            }
        }

        public override int Flags
        {
            get
            {
                return base.ReadStorageInt(UpdateFields.ITEM_FIELD_ENCHANTMENT_4_3);
            }
        }

        public override string Name
        {
            get
            {
                this.name = (string) Globals.playerNames[this.Owner];
                if (this.name != null)
                {
                    return ("Corpse of " + this.name);
                }
                return "";
            }
        }

        public override long Owner
        {
            get
            {
                return base.ReadStorageLong(UpdateFields.OBJECT_END);
            }
        }

        public override float X
        {
            get
            {
                return this.x;
            }
        }

        public override float Y
        {
            get
            {
                return this.y;
            }
        }

        public override float Z
        {
            get
            {
                return this.z;
            }
        }
    }
}

